/**
 * indexDB添加数失败错误类
 */
export default class IndexDBAddDataError<T extends object> extends Error{
    private readonly data: T;
    private readonly originalError: DOMException | null
    private readonly errorName: string | undefined;
    private readonly errorInfo: string | undefined;
    constructor(data: T, originalError: DOMException | null) {
        const msg = originalError ? "ErrorType: " +  originalError.name + "\n\tErrorInfo: " + originalError.message : "";
        super("\n\tErrorData: " + JSON.stringify(data) + "\n\t" +msg);
        this.errorName = originalError?.name
        this.errorInfo = originalError?.message
        this.data = data;
        this.originalError = originalError;
        Object.setPrototypeOf(this, IndexDBAddDataError.prototype);
    }

    toString(){
        return {
            name: this.name,
            errorName: this.errorName,
            errorInfo: this.errorInfo,
            message: this.message,
            data: this.data,
            other: this.originalError
        };
    }
}